<template>
  <div>
    <div class="title">
      <el-row :gutter="20">
        <el-col :span="12" :offset="0">
          申报批次设置
        </el-col>
        <el-col :span="12" :offset="0">
          <div class="right">
            <!-- <el-button type="success" size="mini" @click="clearLimit" :loading="loading">清空项目复制限制</el-button> -->
          </div>
        </el-col>
      </el-row>
    </div>
    <!-- <el-tag type="info" size="normal">每年运维项目只能复制一次，点击“清空项目复制限制”按钮解除复制限制</el-tag> -->
    <div class="container">
      <el-form :model="dateList" ref="dateList" label-position="top" :inline="false" size="normal">
        <el-form-item label="申报批次：">
          <el-date-picker v-model="dateList.apply_batch" type="year" value-format="yyyy" size="normal"
            :clearable="false" placeholder="选择运维申报批次" class="wid">
          </el-date-picker>
          <el-form-item label="申报开始时间：">
            <el-date-picker v-model="dateList.mainStartTime" type="date" value-format="yyyy-MM-dd" size="normal"
              :clearable="false" placeholder="选择运维开始时间" class="wid">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="申报结束时间：">
            <el-date-picker v-model="dateList.mainEndTime" type="date" value-format="yyyy-MM-dd" size="normal"
              :clearable="false" placeholder="选择运维结束时间" class="wid">
            </el-date-picker>
          </el-form-item>
        </el-form-item>
        <div class="center">
          <el-button type="primary" size="default" @click="submit" :loading="loading">保存</el-button>
        </div>
      </el-form>
    </div>

    <div class="title">
      拦标价资产设置
    </div>
    <div class="center">
      <el-button-group>
        <el-button type="primary" size="default" @click="onCopy" :loading="loading">复制“{{dateList.apply_batch}}”批次运维项目细项
        </el-button>
        <el-button type="success" size="default" @click="onUpdate" :loading="loading">更新</el-button>
      </el-button-group>
    </div>

    <el-dialog title="资产更新设置" :visible.sync="show" width="30%">
      <el-form :model="applyList" ref="applyList" label-position="top" size="normal">
        <el-form-item label="项目状态">
          <el-select v-model="applyList.status" value-key="status" class="wid">
            <el-option v-for="item in d_projectStatus" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否有审核金额">
          <el-radio-group v-model="applyList.isFilterThridAmount" size="normal">
            <el-radio-button :label="true">有审核金额</el-radio-button>
            <el-radio-button :label="false">无审核金额</el-radio-button>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div class="center">
        <el-button type="success" size="default" @click="update">更新</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { mapGetters } from 'vuex'
import { d_projectStatus } from '@/utils/dicts'
export default {
  name: 'OperaTotal',
  components: {

  },
  props: {

  },
  data () {
    return {
      loading: false,
      dateList: {},
      show: false,
      applyList: {
        status: '52',
        isFilterThridAmount: true
      },
      d_projectStatus: d_projectStatus
    }
  },
  created () {

  },
  mounted () {
    this.init()
  },
  methods: {
    async init () {
      this.loading = true
      const res = await this.$http('sysApplyDate', {
        source: '1'
      })
      // 好家伙，返回个字符串的null值
      for (let name in res) {
        if (!res[name] || res[name] == 'null') {
          delete res[name]
        }
      }
      this.dateList = res
      this.loading = false
    },
    async clearLimit () {
      this.loading = true
      const res = await this.$http('sysProjectLimit', {
      })
      this.$tips.success(res.errmsg)
      this.loading = false
    },
    async submit () {
      this.loading = true
      const res = await this.$http('sysApplyDateUp', {
        ...this.dateList
      })
      this.$tips.success(res.errmsg)
      this.loading = false
    },
    async onCopy () {
      this.loading = true
      const date = await this.$http('sysApplyDate', {
        source: '1'
      })
      this.$confirm('是否确认复制“' + date.apply_batch + '”批次运维资产', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(async () => {
        const res = await this.$http('sysBlockCopyIt', {
          status: '6',
          isFilterThridAmount: true
        })
        this.$tips.success(res.errmsg)
        this.init()
        this.loading = false
      }).catch(() => {
        this.loading = false
      });

    },
    onUpdate () {
      this.show = true
    },
    update () {
      this.loading = true
      this.$confirm('是否确认更新资产', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(async () => {
        const res = await this.$http('sysBlockUpIt', {
          ...this.applyList
        })
        if (res.errcode === 9999) {
          this.$tips.warning(res.errmsg)
        } else {
          this.$tips.success(res.errmsg)
        }

        this.show = false
        this.init()
        this.loading = false
      }).catch(() => {
        this.loading = false
      });
      // 
    }
  },
  computed: {
    ...mapGetters([
      'user1'
    ])
  }
}
</script>
<style lang='scss' scoped>
</style>
